/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-6-11 下午8:50
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.recycleviewdemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by dqhl on 17/6/11.
 */
public class GuanTextView extends TextView {

    private Paint mPaintOne,mPaintTwo;
    public GuanTextView(Context context) {
        super(context);
        initView();
    }

    public GuanTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public GuanTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView(){
        mPaintOne = new Paint();
        mPaintTwo = new Paint();
        mPaintOne.setColor(getResources().getColor(android.R.color.holo_blue_light));
        mPaintOne.setStyle(Paint.Style.FILL);
        mPaintTwo .setColor(Color.YELLOW);
        mPaintTwo.setStyle(Paint.Style.FILL);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        //在回调父类的方法前,实现自己的逻辑,对TextView来说即是在绘制文本内容之前
        canvas.drawRect(0,0,getMeasuredWidth(),getMeasuredHeight(),mPaintOne);
        canvas.drawRect(10,10,getMeasuredWidth()-10,getMeasuredHeight()-10,mPaintTwo);
        canvas.save();
        //绘制文字前平移10像素
        canvas.translate(10,0);

        super.onDraw(canvas);

        //在回调父类的方法后,实现自己的逻辑,对TextView来说即是在绘制文本内容之前
        canvas.restore();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
